package leetcode.lt100;

class Solution_66 {
	public int[] plusOne(int[] digits) {
		int l = digits.length;
		int current = l - 1;
		digits[current] += 1;
		while (current > 0 && digits[current] == 10) {
			digits[current] = 0;
			digits[current - 1] += 1;
			current--;
		}
		if (digits[0] == 10) {
			int[] res = new int[l + 1];
			res[0] = 1;
			res[1] = 0;
			for (int i = 2; i < l + 1; i++) {
				res[i] = digits[i - 1];
			}
			return res;
		}
		return digits;
	}
}